home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxinfo / kardp14 / karafm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-29  |  4.2 KB  |  193 lines

  1. /*
  2.      KARAOKE
  3.  
  4.      Copyright (c) 1993 94 JP COCATRIX . All rights reserved.
  5. */
  6. /*  This is the interface module used in karados
  7.         given as an explaination of how the resident code like Ultramid
  8.         is used.
  9.         These primitives are called only if the output mode is s (-po=s)
  10.         I Hope it is self documented.
  11.         If loading a patches is no meaning for you, just ignore in the TSR
  12.         The APP_START and APP_END is only a protection for multiple users
  13.         to avoid the remove of the TSR if a program is still using it.
  14.         The key for detection for an other TSR than ULTRAMID
  15.         is KARADOS. Dont use ULTRAMID
  16. */
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <dos.h>
  20.  
  21. #define TSR_LOAD_PATCH                12
  22. #define TSR_UNLOAD_ALL_PATCHES      15
  23. #define TSR_MIDI_OUT                  16
  24. #define TSR_ALL_NOTES_OFF            18
  25. #define TSR_APP_START                  26
  26. #define TSR_APP_END                    27
  27.  
  28. #define control_change              0xB0
  29. #define after_touch                                0xD0
  30.  
  31. extern enum HARD {RIEN,SB,GUS,MPU401,COM1,COM2,COM3,COM4} hardware;
  32. extern void SaySo(char *texte,int multiple);
  33. extern short inrange(unsigned char,unsigned char min,unsigned char max);
  34. extern const char *getInstrument(unsigned char);
  35. void    sbFmSound3(int,int,int );
  36. //*******************************************************************
  37. //                 code Synth. output
  38. //*******************************************************************
  39.  
  40. void (far *um_hook)(void) = 0L;
  41.  
  42.  
  43. void    um_parameter( int channel, int control, int value )
  44. {
  45.     sbFmSound3( (control_change+channel),control,value );
  46. }
  47.  
  48. void    loadpatch( int patch )
  49. {
  50.     char strg[80];
  51.     if (um_hook)
  52.     {
  53.         if (patch <128)
  54.         sprintf(strg,"Loading %s",getInstrument(patch));
  55.         else
  56.         {
  57.             if (!inrange(patch,128+27,128+87)) return;
  58.             sprintf(strg,"Loading drum %d",patch-128);
  59.         }
  60.         SaySo(strg,6);
  61.         _AX = TSR_LOAD_PATCH;
  62.         _CX = patch;
  63.         (*um_hook)();
  64.     }
  65. }
  66.  
  67.  
  68. int    reset_um( )
  69. {
  70.     int i;
  71.  
  72.     _AX = TSR_ALL_NOTES_OFF;
  73.     if (um_hook) (*um_hook)();
  74.     for (i=0; i < 16; i++) {
  75.         um_parameter(i, 0x78, 0); /* all sounds off */
  76.         um_parameter(i, 0x79, 0); /* reset all controllers */
  77.         um_parameter(i, 100, 0); /* RPN MSB 0 */
  78.         um_parameter(i, 101, 0); /* RPN LSB 0 */
  79.         um_parameter(i, 6, 2); /* Pitch Bend Sensitivity MSB */
  80.         um_parameter(i, 38, 0); /* Pitch Bend Sensitivity LSB */
  81.     }
  82.     return(1);
  83. }
  84.  
  85. void    um_cleanup( void )
  86. {
  87.     if (um_hook)
  88.     {
  89.         SaySo("Unload Patches",6);
  90.         _AX = TSR_UNLOAD_ALL_PATCHES;
  91.         (*um_hook)();
  92.         reset_um();
  93.         _AX = TSR_APP_END;
  94.         (*um_hook)();
  95.     }
  96. }
  97.  
  98.  
  99. //***********************************************************************
  100. //                code commun   common code
  101. //***********************************************************************
  102. // name with FM are for historical reasons !!
  103. #pragma warn -par
  104. int    initfm()
  105. {
  106.     int vector, i;
  107.     char far *stamp;
  108.     switch (hardware)
  109.     {
  110.     case GUS:
  111.     case SB:
  112.   case MPU401:
  113.   case COM1:
  114.   case COM2:
  115.   case COM3:
  116.   case COM4:
  117.         for (vector=0x78; vector <= 0x7f; vector++)
  118.         {
  119.             um_hook = (void (far *)())getvect(vector);
  120.             stamp = (char far *)MK_FP( FP_SEG(um_hook), 0x103 );
  121.             if ((strncmp(stamp, "ULTRAMID", 8) == 0)||(strncmp(stamp, "KARADOS", 7) == 0))
  122.                  break;
  123.             stamp = (char far *)MK_FP( FP_SEG(um_hook), FP_OFF(um_hook)+0x04 );
  124.             if ((strncmp(stamp, "ULTRAMID", 8) == 0)||(strncmp(stamp, "KARADOS", 7) == 0))
  125.                  break;
  126.         }
  127.         if (vector <= 0x7f) {
  128.             if (um_hook)
  129.             {
  130.                 _AX = TSR_APP_START;
  131.                 (*um_hook)();
  132.                 reset_um();
  133.             }
  134.         } else
  135.         {
  136.             um_hook = 0L;
  137.           printf (" No synth found.\n");
  138.             return(1);
  139.         }
  140.         return(0);
  141.     case RIEN :
  142.     default:
  143.           printf (" No hard. Sorry.\n");
  144.         return (1);
  145.     }
  146. }
  147. #pragma warn .par
  148.  
  149.  
  150. void    sbFmSound2(int car1, int car2)
  151. {
  152.     if (um_hook)
  153.     {
  154.     switch (hardware)
  155.     {
  156.     case GUS:
  157.     case SB:
  158.             _AX = TSR_MIDI_OUT;
  159.             _CX = car1;
  160.             (*um_hook)();
  161.             _AX = TSR_MIDI_OUT;
  162.             _CX = car2;
  163.             (*um_hook)();
  164.         break;
  165.     default:break;
  166.     }
  167.   }
  168. }
  169.  
  170. void    sbFmSound3(int car1, int car2, int car3)
  171. {
  172.     if (um_hook)
  173.     {
  174.     switch (hardware)
  175.     {
  176.     case GUS:
  177.     case SB:
  178.             _AX = TSR_MIDI_OUT;
  179.             _CX = car1;
  180.             (*um_hook)();
  181.             _AX = TSR_MIDI_OUT;
  182.             _CX = car2;
  183.             (*um_hook)();
  184.             _AX = TSR_MIDI_OUT;
  185.             _CX = car3;
  186.             (*um_hook)();
  187.         break;
  188.     default:break;
  189.     }
  190.   }
  191. }
  192.  
  193.